using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;

namespace IMSAT.OFTD.DOM.DataProxy.Xml
{
    public class XmlReaderAttributeEnumerable:IEnumerable<XmlReader>
    {
        private XmlReader root;

        public IEnumerator<XmlReader> GetEnumerator()
        {
            return new XmlReaderAttributeEnumerator(this);
        }

        public XmlReaderAttributeEnumerable(XmlReader root)
        {
            this.root = root;
        }

        public class XmlReaderAttributeEnumerator : IEnumerator<XmlReader>
        {
            private XmlReaderAttributeEnumerable enumerable;
            private int curent = -1;
            public XmlReaderAttributeEnumerator(XmlReaderAttributeEnumerable enumerable)
            {
                this.enumerable = enumerable;
            }

            public void Dispose()
            {
                enumerable.root.MoveToElement();
            }

            public bool MoveNext()
            {
                curent++;
                return (!(curent >= enumerable.root.AttributeCount))&&enumerable.root.HasAttributes;
            }

            public void Reset()
            {
                curent = -1;
            }

            public XmlReader Current
            {
                get
                {
                    enumerable.root.MoveToAttribute(curent);
                    return enumerable.root;
                }
            }

            object IEnumerator.Current
            {
                get { return Current; }
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}